package com.backend.mzyf.controllers.site;


import com.backend.mzyf.Utils.UploadUtil;
import com.backend.mzyf.Utils.excelUtils.ExcelRead;
import com.backend.mzyf.controllers.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

@Controller
public class IndexController extends BaseController {


    Logger logger = Logger.getLogger(String.valueOf(IndexController.class));

    @RequestMapping("/index")
    public String index()
    {
        return "site/index";
    }

    @RequestMapping("/signin")
    public String login()
    {
        return "site/signin";
    }


    @RequestMapping("/signup")
    public String register(){
        return "site/signup";
    }

    @RequestMapping("/forbidden")
    public String forbidden()
    {
        return "site/403";
    }

    @RequestMapping("/notfound")
    public String notFound()
    {
        return "site/404";
    }

    @RequestMapping("/csrfforbidden")
    public String csrfForbidden()
    {
        return "site/400";
    }

    @RequestMapping("/error")
    public String error()
    {
        return "site/500";
    }

    @RequestMapping("/ws")
    public String webSocket()
    {
        return "ws";
    }

    @RequestMapping("/upload")
    public String upload()
    {
        return "site/upload";
    }

    @RequestMapping(value = "/readExcel",method = {RequestMethod.POST})
    public String readExcel(@RequestParam(value="excelFile") MultipartFile file,
                            HttpServletRequest request, HttpServletResponse response,HttpSession session)
            throws IOException {
        System.out.println(file);
        String fileName = file.getOriginalFilename();
        Long size = file.getSize();

        List<ArrayList<String>> list = new ExcelRead().readExcel(file);

        System.out.println(fileName);
        System.out.println(size);
        System.out.println(list);
        Boolean result = UploadUtil.saveFile(file);
        System.out.println(result);
        return "site/signup";
    }

}
